/*
** my_add_elem_in_tab.c for my_add_elem_in_tab in /home/nadali_t//local/Projets/CprgElem/pushswap
** 
** Made by thomas nadalie
** Login   <nadali_t@epitech.net>
** 
** Started on  Fri Jan  6 14:40:47 2012 thomas nadalie
** Last update Fri Jan  6 15:39:49 2012 thomas nadalie
*/

#include	<stdlib.h>
#include	<push_swap.h>

int	*my_add_elem_in_tab(int *tab, unsigned int pos, int elem)
{
  int	i;
  int	j;
  int	*tmp;

  i = 0;
  j = 0;
  tmp = malloc((my_strlen(tab) + 1) * sizeof(int));
  if (tmp == NULL)
    return (0);
  while (i <= (my_strlen(tab)))
    {
      if (j == pos)
	tmp[j++] = elem;
      tmp[j] = tab[i];
      j++;
      i++;
    }
  return (tmp);
}
